<template>
	<!-- 选择学校 -->
	<view class="locationContent">
		<!-- <uni-search-bar placeholder="请输入学校" bgColor="#EEEEEE" v-model="keyword" @confirm="search" /> -->
		<u-search placeholder="请输入学校" v-model="keyword" @search="search" :show-action="false"></u-search>
		<view class="content">
			<view class="title" @click="getLocation">选择学校</view>
			<view class="schoolList" v-for="(item,index) in schoolList" :key="index"
				@click="eventSelectSchool(item)">
				{{item.store_name}}
			</view>
		</view>
		<!-- 地图 -->
		<!-- <view class="page-body">
			<view class="page-section page-section-gap">
				<map style="width: 100%; height: 300px;" :latitude="latitude" :longitude="longitude" :markers="covers">
				</map>
			</view>
		</view> -->
	</view>
</template>

<script>
	const $api = require('@/utils/request.js').API
	export default {
		data() {
			return {
				keyword: '',
				schoolList: [],
				// id: 0, // 使用 marker点击事件 需要填写id
				// title: 'map',
				// latitude: 39.909,
				// longitude: 116.39742,
				// locat: '',
				// covers: [{
				// 	latitude: 39.909,
				// 	longitude: 116.39742,
				// 	iconPath: '../../../static/location.png'
				// }, {
				// 	latitude: 39.90,
				// 	longitude: 116.39,
				// 	iconPath: '../../../static/location.png'
				// }]
			}
		},
		onLoad() {
			this.postSelectSchool()
		},
		watch: {
			keyword(val){
				if(val == '') {
					this.postSelectSchool()
				}
			},
		},
		methods: {
			postSelectSchool() {
				let obj = {}
				$api.postSelectSchool(obj).then(res => {
					if (res.data.code == 0) {
						this.schoolList = res.data.data.list
					}
				})
			},
			eventSelectSchool(item) {
				uni.setStorage({
					key:'selectSchool',
					data:item,
					success(res) {
						uni.switchTab({
							url:'../../pages/index/index'
						})
					}
				})
				// uni.switchTab({
				// 	url:'../../pages/index/index?item=' + JSON.stringify(item)
				// })
			},
			getLocation() {
				uni.getLocation({
					type: 'gcj02', //返回可用于uni.openLocation的经纬度
					success: function(res) {
						//res.longitude经度
						//res.latitude //维度
					},
					fail: function(err) {
					}
				})
				// let _this = this
				// uni.chooseLocation({
				// 	success: function(res) {
				// 		_this.lat = res.latitude
				// 		_this.lon = res.longitude
				// 		_this.locat = res.latitude + ',' + res.longitude
				// 	}
				// });
			},
			search(val) {
				this.schoolList = this.schoolList.filter(item => {
					return item.store_name.indexOf(val) !== -1
				})
				// uni.showToast({
				// 	title: '搜索：' + res.value,
				// 	icon: 'none'
				// })
			},
			openLocation() {
				uni.openLocation({
					latitude: 39.9,
					longitude: 116.4,
					name: '学校',
					address: ''
				})
			}
		}
	}
</script>

<style>
	.locationContent {
		padding: 20rpx 30rpx;
	}

	.u-action-active,
	.u-action {
		color: #F14500;
	}

	.title {
		margin-top: 26rpx;
		height: 72rpx;
		line-height: 72rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #262626;
		line-height: 30rpx;
	}

	.schoolList {
		height: 72rpx;
		line-height: 72rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #545454;
		line-height: 30rpx;
	}
</style>